﻿/////////////////////////////////////////////////////////////////
//File: BlogManager.cs
//Description: 此文件是根据facade模式和接口隔离原则创建的。各个子业务之间的关联在这里建立。 
//            
//Copyright© 2011 Moliu
//History:
//  2011-3-26 18:11:20    CodeSmith5.0.1    Original Version
//  2011-3-26 19:26:20    Moliu             1
//  2011-4-17 13:13:15    Moliu             2
//  2011-4-23 12:21:49    Moliu             3
//  2011-4-22 22:10:12    Moliu             4
/////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Security.Permissions;
using System.Transactions;
using System.Configuration;

using MAF.Common;
using MAF.Common.Security;
using My.Blog.Domain.Entities;
using My.Blog.Domain.Interfaces;
using My.Blog.Business.Persistence;
using My.Blog.Business.Security;

namespace My.Blog.Business.Service
{
    public partial class FileSvc : IFile
    {
        IFile _File = DaoFactory.Instance.CreateFile();

        #region 构造函数
        public FileSvc() 
        {
        }
        #endregion

        #region IFile成员，核心接口
        ///<summary>
        /// CreateFile
        ///</summary>
        public void CreateFile(FileInfo info,System.IO.Stream stream)
        {
            if (1 > stream.Length)
                return;

            // 保存文件
            FileStorageStrategy fss = new DefaultFileStorageStragy(ConfigurationManager.AppSettings["FileServerPath"], 100, 500);
            string[] ss = fss.Save(stream, info.FileType);

            info.Id = CombGuid.NewComb();
            info.FileName = ss[1];
            info.DateCreated = DateTime.Now;
            
            _File.CreateFile(info,null);
        }

        ///<summary>
        /// UpdateFile
        ///</summary>
        public int UpdateFile(FileInfo info)
        {
            //IFile _File = DaoFactory.Instance.CreateFile();

            info.DateModified = DateTime.Now;
            return _File.UpdateFile(info);
        }

        ///<summary>
        /// DeleteFiles
        ///</summary>
        public int DeleteFiles(FileInfo info)
        {
            //IFile _File = DaoFactory.Instance.CreateFile();

            return _File.DeleteFiles(info);
        }

        ///<summary>
        /// ReadFileByConditions
        ///</summary>
        public FileInfo ReadFileByConditions(FileInfo info)
        {
            //IFile _File = DaoFactory.Instance.CreateFile();

            return _File.ReadFileByConditions(info);
        }

        ///<summary>
        /// ReadFilesByConditions
        ///</summary>
        public IList<FileInfo> ReadFilesByConditions(FileInfo info, int pageSize, int currentPage)
        {
            //IFile _File = DaoFactory.Instance.CreateFile();

            PageInfo page = new PageInfo(pageSize, currentPage);
            page.RecordCount = _File.ReadFilesCountByConditions(info);
            return _File.ReadFilesByConditions(info, page.PageSize, page.CurrentPage);
        }

        ///<summary>
        /// ReadFilesCountByConditions
        ///</summary>
        public int ReadFilesCountByConditions(FileInfo info)
        {
            //IFile _File = DaoFactory.Instance.CreateFile();

            return _File.ReadFilesCountByConditions(info);
        }
        #endregion

        //================================
        // 上面是自动生成的代码,下面是手工编写的代码
        //================================ 
    }
}
